﻿
namespace LFSRecord2.Misc
{
    public class ByteBuffer
    {
        byte[] _buf;
        public byte[] Buf
        {
            get { return _buf; }
        }
        EndianTypes _endian;

        public int Position { get; set; }

        public ByteBuffer(int size) : this(size, EndianTypes.Big) { }
        public ByteBuffer(int size, EndianTypes endian)
        {
            _buf = new byte[size];
            _endian = endian;
            Position = 0;
        }

        public void ReadBytes(byte[] toBuf, int offset, int length)
        {
            length += offset;
            if (_endian == EndianTypes.Little)
            {
                length--;
                for (int a = length; a >= offset; a--)
                {
                    toBuf[a] = _buf[Position++];
                }
            }
            else
            {
                for (int a = offset; a < length; a++)
                {
                    toBuf[a] = _buf[Position++];
                }
            }
        }
    }
}
